using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace OpenMTS
{
    public partial class NewProjectDialog : Form
    {

        #region VARIABLES
        private const string DefaultProjectName = @"Project1";
         
        #endregion

        #region CONSTRUCTORS
        public NewProjectDialog()
        {
            InitializeComponent();
            txtProjectName.Text = DefaultProjectName;
            this.btnOK.Enabled = false;
            
        }
        #endregion

        #region ACCESSORS

        

        public string ProjectName
        {
            get { return txtProjectName.Text; }
        }

        public string ProjectLocation
        {
            get { return txtLocation.Text; }
        }
        #endregion

        #region EVENTS
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            DialogResult dlgResult = dlg.ShowDialog();
            if (dlgResult == DialogResult.OK)
            {
                this.txtLocation.Text = dlg.SelectedPath;
            }
            
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            //TODO: Create the project directory if it does not exist
           // System.IO.DirectoryInfo i = new System.IO.DirectoryInfo(txtLocation.Text);
           // if(!i.Exists)
                
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        

        private void txtLocation_TextChanged(object sender, EventArgs e)
        {
            //Make a simple attempt at having a valid path
            Regex r = new Regex(@"[a-zA-Z]:\\", RegexOptions.IgnoreCase);
            Match m = r.Match(txtLocation.Text);
            
            btnOK.Enabled = m.Success;
        }

        #endregion
    }
}